<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layuimini-main">

        <form class="layui-form" action="">
            <input type="hidden" name="member_code" value="{$memberCode}">

            <div class="layui-form-item">
                <label class="layui-form-label">团队名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$teamTitle}" lay-verify="title" autocomplete="off" placeholder="团队名称" class="layui-input iwidth" aria-disabled="true">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">团队领导</label>
                <div class="layui-input-block" style="display: flex">
                    <input type="text" name="" value="{$memberName}" autocomplete="off" placeholder="" class="layui-input iwidth" disabled>
                    <button data-method="offset" type="button" data-type="auto" class="layui-btn layui-btn-sm  "  onclick='clickMember("{$memberCode}")' style="margin-top: 4px;margin-left: 10px">查看</button>
                </div>
                <div>


                </div>
            </div>

            <div class="layui-form-item" >
                <label class="layui-form-label">匹配类型</label>

                <div class="layui-input-block" >
                    <input type="radio" name="matching_type" value="1"  lay-filter="radio"  title="独立匹配" checked>
                    <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>独立匹配</div></div>

                    <input type="radio"  name="matching_type" value="2"  lay-filter="radio"   title="综合匹配">
                    <div class="layui-unselect layui-form-radio" ><i class="layui-anim layui-icon"></i><div>综合匹配</div></div>

                </div>
            </div>
            <!--<div class="layui-form-item" >
                &lt;!&ndash;筛选开始&ndash;&gt;
                <div class="layui-inline">
                    <label class="layui-form-label">搜索</label>
                    <div class="layui-input-inline">
                        <input type="text" name="search" id="searchuser" value="" lay-verify="" placeholder="请根据团队名称搜索" class="layui-input ">
                    </div>
                </div>

                <div class="layui-inline">
                    <button type="button" class="layui-btn" onclick="souTeam()" > <i class="layui-icon"></i> 搜 索</button>
                </div>
            </div>-->

            <div class="layui-form-item" id="checkboxTeam" style="display:none">
                <label class="layui-form-label">团队名称</label>
                <div class="layui-input-block" style=" padding:0px 0px 10px;box-sizing:border-box;width:1200px;overflow: auto;display: flex;flex-wrap: wrap;justify-content: flex-start">
                    <div style="width:200px">
                        <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary" title="全选">

                    </div>
                    {volist name="memberTeam" id="v"}

                    <div style="width:200px">
                        <input type="checkbox" class="checkboxs" name="team_set[]" value="{$v.id}" lay-skin="primary"  title="{$v.title}" >

                    </div>

                    {/volist}

                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="add">立即保存</button>
                </div>
            </div>
        </form>

    </div>
</div>

{include file="public/footer" /}

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate','wangEditor'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , wangEditor = layui.wangEditor
            , $ = layui.jquery;
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            console.log(data);
            if (data.elem.checked) {
                $('.checkboxs').prop('checked', true);
            } else {
                $('.checkboxs').prop('checked', false);
            }
            form.render('checkbox');
        });
        $(this).removeAttr("lay-key");//时间框一点就消失处理
        // 上架开始日期
        var insShelf = laydate.render({
            elem: '#create_time'
            , min: 0
            , trigger : 'click'//时间框一点就消失处理
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
             /*   //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });*/

                //自动弹出结束日期的选择器
                //insUnder.config.elem[0].focus();
            }
        });
        form.on('radio(radio)', function(data){
            if(data.value == 1){
                //独立匹配
                document.querySelector("#checkboxTeam").style.display='none';
            }else if(data.value == 2){
                //综合匹配
                document.querySelector("#checkboxTeam").style.display='block';
            }

        });
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value == '') {
                    return '团队名称不能为空';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交修改
        form.on('submit(add)', function (data) {
            let  postdata =data.field
            // postdata.answer=editor.txt.html()
            $.ajax({
                url: '/admin/team/create?active=teamCreate&action=ajax&memberName={$memberName}&memberCode={$memberCode}&teamTitle={$teamTitle}',
                type: 'post',
                dataType: 'json',
                data: postdata,
                success: function (res) {
                    if (res.status == true) {    // 获得frame索引
                        parent.layer.msg("操作成功!",
                            {
                                icon:1,
                                time: 1000
                            },
                            function () {
                            //重新加载父页面
                                parent.parent.parent.location.reload();
                        });
                        return;
                    } else{
                        layer.msg(res.msg,{ icon:5,
                            time: 1000});
                    }
                },
                error: function () {
                    layer.msg("报错了");
                }
            });
            return false;
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })*/
        });


    });
    //查看用户信息
    function clickMember(memberCode){
        var index = layer.open({
            title:'领导人信息',
            type: 2,
            area: ['100%', '100%'],
            fixed: false, //不固定
            shade:0.5,
            shadeClose:true,
            content: '/admin/team/getMember?memberCode='+memberCode,
        });
        return false;


    }
    //搜索
    function souTeam(){
        var search = $("input[name='search']").val();
        $.ajax({
            url: "/admin/notice/create?type={$type}",
            type: 'post',
            async:true,
            data:{search:search},
            dataType: 'json',
            success: function (res) {
                if(res.status == true){
                    $(".showuser").html(res.param);
                    form.render()
                }else{
                    layer.msg(res.msg,{icon:5,time: 1000})
                }

            },
            error: function (res) {
                console.log(res);
            }
        });

    }

</script>
</body>
</html>